
public class ContainWater {

	  public int maxArea(int[] height) {
	      
		  int result[][]=new int[2][height.length];
		  
		  int maxHeight=height[0];
		  
		  for(int i=0;i<height.length;i++){
			  if(height[i]>maxHeight){
				  maxHeight=height[i];
			  }
			  result[0][i]=maxHeight-height[i];
		  }
		  
		  maxHeight=height[height.length-1];
		  
		  for(int i=height.length-1;i>=0;i--){
				  if(height[i]>maxHeight){
					  maxHeight=height[i];
				  }
				  result[1][i]=maxHeight-height[i];
		  }
		  
		  int count=0;
		  for(int i=0;i<height.length;i++){
			  if(result[0][i]<result[1][i])
				  count+=result[0][i];
			  else
				  count+=result[1][i];
		  }
		  return count;
	  }
}
